#coding:utf-8
import requests
from requests.exceptions import  ConnectionError
from urllib.parse import urlencode
import time

base_url='https://www.zhihu.com/search?'

headers={
    'Request URL':'https://www.zhihu.com/search?type=content&q=%E9%9C%8D%E9%87%91',
    'Request Method':'GET',
    'Status Code':'200 OK',
    'Remote Address':'118.178.213.186:443',
    'Referrer Policy':'no-referrer-when-downgrade',
    'Cookie':'q_c1=3da8b1ce6221411ab95008c6de1115ca|1514960877000|1514960877000; _zap=65f6b46b-f4ba-4a92-9f6a-e60a30d935ba; z_c0="2|1:0|10:1514969689|4:z_c0|92:Mi4xMmdKVUFnQUFBQUFBc0tCWmZkenVEQ1lBQUFCZ0FsVk5XZWc1V3dBOC1jUHF5UEh4cFVKb1FNMFU3elQ5cUYtbV9R|a4082bfd78b6f69851c9679ab07d2478b5d5f3414c0ddbc618ce6f16aef96425"; d_c0="AEAsQ1T-GA2PTnoofojEEUkcxWVFx3igflw=|1517795582"; __utmz=155987696.1517823033.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); q_c1=3da8b1ce6221411ab95008c6de1115ca|1520469082000|1514960877000; __utma=155987696.159799334.1517823033.1517823033.1520683562.2; aliyungf_tc=AQAAAEX9RC6rcwMAWBQKcHTiJEHzt5Tt; _xsrf=9227eba1-09ee-449f-b8fd-68db72425aac',
    'Host':'www.zhihu.com'
}

keyword='霍金'
max_count=10

def get_html(url,count=1):
    print('crawing ',url)
    print('try times ',count)
    response = requests.get(url, allow_redirects=False, headers=headers)
    if response.status_code == 200:
        return response.text  # 返回url的html源码
    if response.status_code == 302:
        print(url + ' response 302')
